package com.zjl.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.zjl.util.QueryDataResult;
import com.zjl.entity.StudentEntity;
import com.zjl.util.DBManager;
import com.zjl.util.QueryDataResult;

public class StudentDaoImpl {
	public ArrayList<StudentEntity> selectAll(String name) {
		ArrayList<StudentEntity> alist= new ArrayList<StudentEntity>();
	    String sqlString;
	    if (name!=null&&!name.equals("")) {
	      sqlString="select stu_id,stu_name,sex,mtel,qq,address,class_name from students where stu_name like '%"+name+"%'";
	    }else {
	       sqlString="select stu_id,stu_name,sex,mtel,qq,address,class_name from students";
	    }
	    QueryDataResult rSet=DBManager.excuteQuery(sqlString);
	      if (rSet!=null) {
	        try {
	          while (rSet.rs.next()) {
	            alist.add(new StudentEntity(rSet.rs.getInt("stu_id"),
	            		rSet.rs.getString("stu_name"),
	            		rSet.rs.getString("sex").charAt(0),
	            		rSet.rs.getString("mtel"),rSet.rs.getString("qq"),
	            		rSet.rs.getString("address"),rSet.rs.getString("class_name")));
	          }
	        } catch (SQLException e) {
	          e.printStackTrace();
	        }
	      }
	      rSet.close();
	    return alist;
	}
	

}
